﻿package mortal.game.view.rebate.openServerSevenDay.item
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.item.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class OpenServerSevenTabCell extends RebateTabBaseCell
    {
        protected var _btn:GLoadingButton;
        protected var _title:GBitmap;
        private var _selectBmp:GBitmap;
        private var _selectFlag:Boolean = false;
        private var skinName:String = "";
        private var _isLastOne:Boolean = false;

        public function OpenServerSevenTabCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._btn = UIFactory.gLoadingButton(ImagesConst.OpenServerSevenDayLeftTab_upSkin, 0, 0, 122, 42, this);
            this._btn.label = "";
            this._selectBmp = UIFactory.bitmap("", 0, 0, this);
            this._title = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayTab1, 22, 13, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._btn.dispose(param1);
            this._title.dispose(param1);
            this._btn = null;
            this._title = null;
            if (this._selectBmp)
            {
                this._selectBmp.dispose();
                this._selectBmp = null;
            }
            LoaderHelp.removeResEvent(this.skinName, this.setStyl);
            this.skinName = "";
            this._selectFlag = false;
            return;
        }// end function

        private function setStyl() : void
        {
            if (this._btn && this.skinName != "")
            {
                this._selectBmp.bitmapData = GlobalClass.getBitmapData(this.skinName + "_overSkin");
                if (this._isLastOne)
                {
                    this._selectBmp.width = 108;
                }
                else
                {
                    this._selectBmp.width = 122;
                }
                this._selectBmp.visible = this._selectFlag;
            }
            return;
        }// end function

        public function set isSelect(param1:Boolean) : void
        {
            if (this._selectFlag != param1)
            {
                this._selectFlag = param1;
                if (this._selectBmp)
                {
                    this._selectBmp.visible = this._selectFlag;
                }
            }
            return;
        }// end function

        override public function setData(param1) : void
        {
            super.setData(param1);
            if (param1 == null)
            {
                return;
            }
            this._title.dispose();
            var _loc_2:* = int(info.dayNum);
            this.updateBtn(_loc_2);
            this.updateTitle(_loc_2);
            this.setGray(_loc_2);
            return;
        }// end function

        private function setGray(param1:int) : void
        {
            var _loc_2:* = OpenServerSevenDayUtil.getOpenServerDayNum();
            if (OpenServerSevenDayUtil.PowNum == param1 || OpenServerSevenDayUtil.LevelNum == param1)
            {
            }
            else if (_loc_2 > param1)
            {
                this.filters = [FilterConst.colorFilter2];
            }
            else
            {
                this.filters = null;
            }
            return;
        }// end function

        private function updateBtn(param1:int) : void
        {
            this._isLastOne = this.isLast(param1);
            this._btn.dispose();
            if (OpenServerSevenDayUtil.PowNum == param1)
            {
                this._btn = UIFactory.gLoadingButton(ImagesConst.OpenServerSevenDayLeftTab_upSkin, 0, 0, 122, 42);
                this.skinName = "OpenServerSevenDayLeftTab";
            }
            else if (this._isLastOne)
            {
                this._btn = UIFactory.gLoadingButton(ImagesConst.OpenServerSevenDayRightTab_upSkin, 0, 0, 108, 42);
                this.skinName = "OpenServerSevenDayRightTab";
            }
            else
            {
                this._btn = UIFactory.gLoadingButton(ImagesConst.OpenServerSevenDayMidTab_upSkin, 0, 0, 122, 42);
                this.skinName = "OpenServerSevenDayMidTab";
            }
            this.addChildAt(this._btn, 0);
            LoaderHelp.addResCallBack(this.skinName, this.setStyl);
            return;
        }// end function

        private function isLast(param1:int) : Boolean
        {
            var _loc_2:* = OpenServerSevenDayUtil.LastDayNum;
            if (_loc_2 != 0 && _loc_2 == param1)
            {
                return true;
            }
            return false;
        }// end function

        private function updateTitle(param1:int) : void
        {
            switch(param1)
            {
                case OpenServerSevenDayUtil.PowNum:
                {
                    this._title = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayTabPower, 22, 13, this);
                    break;
                }
                case OpenServerSevenDayUtil.LevelNum:
                {
                    this._title = UIFactory.gBitmap(ImagesConst.OpenServerSevenDayTabLevel, 22, 13, this);
                    break;
                }
                default:
                {
                    this._title = UIFactory.gBitmap(ImagesConst["OpenServerSevenDayTab" + param1], 22, 13, this);
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
